package com.example.healing.controller;

import com.example.healing.common.lang.Result;
import com.example.healing.entity.UserSongList;
import com.example.healing.service.UserSongListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author neymar
 * @date 2021年11月30日 15:41
 */
@EnableSwagger2
@RestController
@Api(tags = "用户歌单")
@RequestMapping("/usersonglist")
public class UserSongListController {

    @Autowired
    private UserSongListService userSongListService;

    /**
     * @author neymar
     * @date 2021/12/1 21:27
     * @param list
     * @return com.example.healing.common.lang.Result
     * @description 创建歌单
     */
    @RequiresAuthentication
    @ApiOperation(value = "创建歌单（需要带token）")
    @PostMapping("")
    public Result create(@Validated @RequestBody @ApiParam("歌单信息") UserSongList list) {
        return userSongListService.create(list);
    }

    /**
     * @author neymar
     * @date 2021/12/1 21:28
     * @param list
     * @return com.example.healing.common.lang.Result
     * @description 删除歌单
     */
    @RequiresAuthentication
    @ApiOperation(value = "删除歌单（需要带token）")
    @DeleteMapping("")
    public Result delete(@Validated @RequestBody @ApiParam("歌单信息") UserSongList list) {
        return userSongListService.delete(list);
    }

    /**
     * @author neymar
     * @date 2021/12/1 21:31
     * @param list
     * @return com.example.healing.common.lang.Result
     * @description 修改歌单信息
     */
    @RequiresAuthentication
    @ApiOperation(value = "修改歌单信息（需要带token）")
    @PutMapping("")
    public Result edit(@Validated @RequestBody @ApiParam("歌单信息") UserSongList list) {
        return userSongListService.edit(list);
    }

    /**
     * @author neymar
     * @date 2021/12/1 21:39
     * @param uid
     * @return com.example.healing.common.lang.Result
     * @description 获取用户的歌单信息
     */
    @RequiresAuthentication
    @ApiOperation(value = "获取用户的歌单信息（需要带token）")
    @GetMapping("/{uid}")
    public Result getSongList(@ApiParam("用户id") @PathVariable("uid") String uid) {
        return userSongListService.getSongList(uid);
    }
}
